package com.breeze.components.core.util.json.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;
import java.math.BigDecimal;

/**
 * BigDecimal为0.00或为整数则去掉小数，看情况用
 *
 * @author breeze
 */
public class BigDecimalStripTailZeroSerializer extends JsonSerializer<BigDecimal> {

  @Override
  public void serialize(BigDecimal value, JsonGenerator gen, SerializerProvider serializers)
      throws IOException {
    gen.writeNumber(value.stripTrailingZeros());
  }
}
